package com.ruoyi.web.controller.mes;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.excel.util.MapUtils;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.file.filedown;
import com.ruoyi.web.controller.mes.report.PersionReportController;
import com.ruoyi.web.domain.MesWarehousingDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.MesWarehousingInfo;
import com.ruoyi.web.service.IMesWarehousingInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库基本信息Controller
 * 
 * @author wxt
 * @date 2024-01-15
 */
@Api("纸张入库单管理")
@RestController
@RequestMapping("/mes/Warehousing/info")
public class MesWarehousingInfoController extends BaseController
{
    @Autowired
    private IMesWarehousingInfoService mesWarehousingInfoService;

    /**
     * 查询入库基本信息列表
     */
    @ApiOperation("查询入库基本信息列表")
    @GetMapping("/list")
    public TableDataInfo list(MesWarehousingInfo mesWarehousingInfo)
    {
        startPage();
        List<MesWarehousingInfo> list = mesWarehousingInfoService.selectMesWarehousingInfoList(mesWarehousingInfo);
        return getDataTable(list);
    }

    /**
     * 纸张入库明细查询
     */
    @ApiOperation("纸张入库明细查询")
    @PostMapping("/Detail")
    public TableDataInfo Detail(@RequestBody Map<String,Object> params)
    {
        PageHelper.startPage((Integer) params.get("pageNum"), (Integer) params.get("pageSize"));
        //startPage();
        MesWarehousingDetail Detail=new MesWarehousingDetail();
        Detail.setParams(params);
//        String w_code = params.get("warehousing_code");//入库单编码
//        String s_name = params.get("custom_name");//供应商名称
//        String code = params.get("code");//纸张编码
//        String o_code = params.get("original_code");//自有编码
//        String name = params.get("name");//纸张名称
//        String startDate =params.get("startDate");//入库时间
//        String endDate = params.get("endDate");//入库时间
        List<MesWarehousingDetail> list = mesWarehousingInfoService.selectMesDetaillist(Detail);
        return getDataTable(list);
    }


    @ApiOperation("导出纸张入库明细")
    @Log(title = "导出纸张入库明细", businessType = BusinessType.EXPORT)
    @PostMapping("/exportWarehousingDetail")
    public void exportWarehousingDetail(HttpServletResponse response,@RequestBody Map<String,Object> params) throws IOException
    {
        MesWarehousingDetail Detail=new MesWarehousingDetail();
        Detail.setParams(params);
        List<MesWarehousingDetail> list = mesWarehousingInfoService.selectMesDetaillistExport(Detail);
           /*
         * 获取模版位置
         * */
        InputStream inputStream= PersionReportController.class.getClassLoader().getResourceAsStream("temlates/warehousingPaper.xlsx");
        filedown  filedownexcel=new filedown();

        String name="纸张入库明细";
        Map<String,Object> map= MapUtils.newHashMap();
      //  map.put("date",date);
        /*
         * 引入方法传入集合、response,模版的输入流
         * */
        filedownexcel.filedownexcels(list,response,name,inputStream,map);

//        ExcelUtil<MesWarehousingDetail> util = new ExcelUtil<MesWarehousingDetail>(MesWarehousingDetail.class);
//        util.exportExcel(response, list, "纸张入库明细");
    }

    /**
     * 导出入库基本信息列表
     */
    @ApiOperation("导出入库基本信息列表")
    @Log(title = "入库基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesWarehousingInfo mesWarehousingInfo)
    {
        List<MesWarehousingInfo> list = mesWarehousingInfoService.selectMesWarehousingInfoList(mesWarehousingInfo);
        ExcelUtil<MesWarehousingInfo> util = new ExcelUtil<MesWarehousingInfo>(MesWarehousingInfo.class);
        util.exportExcel(response, list, "入库基本信息数据");
    }

    /**
     * 获取入库基本信息详细信息
     */
    @ApiOperation("获取入库基本信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mesWarehousingInfoService.selectMesWarehousingInfoById(id));
    }

    /**
     * 新增入库基本信息
     */
    @ApiOperation("新增入库基本信息")
    @Log(title = "入库基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesWarehousingInfo mesWarehousingInfo)
    {
        return toAjax(mesWarehousingInfoService.insertMesWarehousingInfo(mesWarehousingInfo));
    }

    /**
     * 修改入库基本信息
     */
    @ApiOperation("修改入库基本信息")
    @Log(title = "入库基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesWarehousingInfo mesWarehousingInfo)
    {
        return toAjax(mesWarehousingInfoService.updateMesWarehousingInfo(mesWarehousingInfo));
    }

    /**
     * 删除入库基本信息
     */
    @ApiOperation("删除入库基本信息")
    @Log(title = "入库基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mesWarehousingInfoService.deleteMesWarehousingInfoByIds(ids));
    }
}
